/**
 * Generate a JS Object information. 
 * 
 * @param obj: JavaScript Object (instance);
 *
 * @return A string to describle the object information.
 */
ihelpuoo.dump = function(obj)
{
	var info = "[OBJECT]:\r\n{\r\n";
	for(var entity in obj)
	{
		var entityType = typeof obj[entity];
		info += "\t[" + entityType + "]:" + ihelpuoo.dup(".",10-entityType.length) + "\"" + entity + "\"\r\n";
	}
	info += "}";
	return info;
}

/**
 * Duplicate a string [n] times
 * If [n] is 0, return "" (empty string);
 * 
 * @param str:	template str
 * @param n: 	duplicate time.
 *
 * @return A string to describle the object information.
 */
ihelpuoo.dup = function(str,n)
{
	var re = "";
	for(var i=0;i<n;i++) re+=str;
	return re;
}

/**
 * @param str: Original string
 * @param sub: Sub string
 * 
 * @return sub string is at the begin of orignal string or not.
 */
ihelpuoo.startsWith = function(str,sub)
{
	if(!str) return false;
	if(!sub) return false;
	if(sub.length==1)
	{
		if(str.length==0)return false;
		return str.charAt(0)==sub.charAt(0);
	}
	return str.substring(0,sub.length)==sub;
}

/**
 * @param str: Original string
 * @param sub: Sub string
 * 
 * @return sub string at the end of orignal string or not.
 */
ihelpuoo.endsWith = function(str,sub)
{
	if(!str) return false;
	if(!sub) return false;
	if(sub.length==1)
	{
		if(str.length==0)return false;
		return str.charAt(str.length-1)==sub.charAt(0);
	}
	return str.substring(str.length-sub.length,str.length)==sub;
}

/**
 * @param str: Original string
 * 
 * @return A string without head and tail blank char.
 */
ihelpuoo.trim = function(str)
{
	if(null==str) return null;
	if(str.length==0) return str;
	var head = 0;
	for(;head<str.length;head++)
	{
		if(str.charCodeAt(head)>32)break;
	}
	var tail=str.length-1;
	for(;tail>head;tail--)
	{
		if(str.charCodeAt(tail)>32)break;
	}
	return str.substring(head,tail+1);
}

ihelpuoo.trimLeftBy = function(str,sub)
{
	if(ihelpuoo.startsWith(str,sub))
		return ihelpuoo.trimLeftBy(str.substring(sub.length),sub);
	return str;
}

ihelpuoo.dumpRect = function(rect)
{
	var s = "[w:" + rect.width;
	s += " / h:" + rect.height;
	s += " / t:" + rect.top;
	s += " / l:" + rect.left;
	s += "]";
	return s;
}

ihelpuoo.dumpPoint = function(p)
{
	var s = "[x:" + p.x;
	s += " / y:" + p.y + "]";
	return s;
}

ihelpuoo.equals = function(s1,s2)
{
	if(null==s1 || null==s2) return false;
	return s1 == s2;
}

ihelpuoo.equalsIgnoreCase = function(s1,s2)
{
	if(null==s1 || null==s2) return false;
	return s1.toLowerCase()  == s2.toLowerCase;
}

ihelpuoo.isBlank = function(s)
{
	if(null==s || s.length==0)return true;
	for(var i=0;i<s.length;i++)
		if(s.charCodeAt(i)>32)
			return false;
	return true;
}

ihelpuoo.isEmpty = function(s)
{
	if(null==s || s.length==0)return true;
	return false;
}

ihelpuoo.fullLeft = function(d,sub,len)
{
	d = new String(d);
	if(d.length>=len) return d;
	if(sub.length==1)
	{
		var pre = ihelpuoo.dup(sub,len-d.length);
		return pre+d;
	}
	alert("ihelpuoo.fullLeft no support yet!");
	/*
	var max = Math.floor((len-d.length)/sub.length);
	var pre = "";
	if(max>0)
		pre = ihelpuoo.dup(sub,max);
	
	pre += sub.substring(0,sub.length-pre.length);
	*/
}

ihelpuoo.escapeInnerHTMLString = function(s)
{
	if(null==s)return s;
	return s.replace(/</g,"&lt;");
}